package com.xn.app.muying.fragment;


import android.app.AlertDialog;
import android.app.DatePickerDialog;
import android.app.Dialog;
import android.app.TimePickerDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.DatePicker;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.TimePicker;

import com.xn.app.muying.R;
import com.xn.app.muying.adpter.AdviceChanKeAdapter;

import java.util.ArrayList;
import java.util.Calendar;

/**
 * Created by Administrator on 2016/10/10.
 */
public class AdviceFragment extends Fragment implements View.OnClickListener {
    private  TextView shijian_tv;
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        return inflater.inflate(R.layout.advice_fragment_login_content,container,false);
    }

    @Override
    public void onViewCreated(View view, Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        TextView chanke_tv = (TextView) view.findViewById(R.id.chanke_tv);
        shijian_tv = (TextView) view.findViewById(R.id.shijian_tv);
        chanke_tv.setOnClickListener(this);
        shijian_tv.setOnClickListener(this);
    }


    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.chanke_tv:
                AlertDialog.Builder myBuilder = new AlertDialog.Builder(getActivity());
                View inflate = LayoutInflater.from(getActivity()).inflate(R.layout.advice_chanke_listview, null);
                ListView chanke_listview = (ListView) inflate.findViewById(R.id.advice_chanke_lv);

                //暂时模拟的数据
                ArrayList<Integer> list = new ArrayList();
                list.add(1);
                list.add(2);
                list.add(3);

                myBuilder.setView(inflate);
                final AlertDialog create = myBuilder.create();
                AdviceChanKeAdapter chanKeAdapter = new AdviceChanKeAdapter(getActivity(),list);
                chanke_listview.setAdapter(chanKeAdapter);
                create.show();
                break;

            case R.id.shijian_tv:
                Calendar instance = Calendar.getInstance();
                DatePickerDialog pickerDialog = new DatePickerDialog(getActivity(),
                        new DatePickerDialog.OnDateSetListener() {
                            private StringBuffer stringBuffer;
                            @Override
                            public void onDateSet(DatePicker view, int year,
                                                  int monthOfYear, int dayOfMonth) {
                                stringBuffer = new StringBuffer("");
                                stringBuffer.append(year + "-" + (monthOfYear + 1) + "-" + dayOfMonth + " ");
                                shijian_tv.setText(""+stringBuffer);
                            }
                        }, instance.get(Calendar.YEAR),
                        instance.get(Calendar.MONTH),
                        instance.get(Calendar.DAY_OF_MONTH));
                pickerDialog.setTitle("日期");
                pickerDialog.setMessage("请选择预约时间");
                pickerDialog.show();
                break;

        }
    }
}
